<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
    <xsl:param name="DOTNET2"/>
    

  
	<xsl:template match="Class">
		<xsl:variable name="Name" select="Name"/>
        <xsl:variable name="HeaderInfo" select="HeaderInfo/ProjectName"/>



// **************************************************************
// COUCH DB <xsl:value-of select="Name"/> CLASS
// Project Name: <xsl:value-of select="HeaderInfo/ProjectName"/>
// Prefix: <xsl:value-of select="HeaderInfo/Prefix"/>
// **************************************************************

using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace <xsl:value-of select="HeaderInfo/ProjectName"/>.DataObject  {

	[DataContract]
	public class <xsl:value-of select="Name"/> : DalCouch.CouchBase&lt;<xsl:value-of select="Name"/>&gt; , DalCouch.ICouch
	{
		#region Properties
		<xsl:apply-templates select="ClassAttribs/ClassAttributes"/>
		#endregion
		
		
		#region Methods
		<xsl:for-each select="ClassAttribs/ClassAttributes">
			<xsl:if test="CType='single' and Type!='DateTime' and KnownClass='false'">
		public static <xsl:value-of select="$Name"/>[ ] Get_<xsl:value-of select="PropertyName"/> ( <xsl:value-of select="Type"/> key )
		{
			return new <xsl:value-of select="$Name"/> ( ).LoadPropEq ( key.ToString ( ) );
		}
			</xsl:if>
			
			<xsl:if test="CType='single' and Type='DateTime'">
		public static <xsl:value-of select="$Name"/>[ ] Get_<xsl:value-of select="PropertyName"/> ( <xsl:value-of select="Type"/> key )
		{
			return new <xsl:value-of select="$Name"/> ( ).LoadPropEq ( "<xsl:value-of select="Name"/>" , key.Ticks.ToString ( ) );
		}			
			</xsl:if>
			
			<xsl:if test="CType='single' and KnownClass='true'">
		public static <xsl:value-of select="$Name"/>[ ] Get_<xsl:value-of select="PropertyName"/> ( <xsl:value-of select="Type"/> key )
		{
			return new <xsl:value-of select="$Name"/> ( ).LoadPropEq ( "<xsl:value-of select="Name"/>" , key._id );
		}	

		public static <xsl:value-of select="$Name"/>[ ] Get_<xsl:value-of select="PropertyName"/> ( string key )
		{
			return new <xsl:value-of select="$Name"/> ( ).LoadPropEq ( "<xsl:value-of select="Name"/>" , key );
		}	
			</xsl:if>
		</xsl:for-each>
		#endregion
	}
	


}

	</xsl:template>
	
	
	
	<xsl:template match="ClassAttributes">
		<xsl:if test="Type='DateTime' and CType='single'">
		[IgnoreDataMember]
		public DateTime <xsl:value-of select="PropertyName"/> { get; set; }
		
		[DataMember]
		protected long <xsl:value-of select="Name"/>
		{ 
			get 
			{ 
				return <xsl:value-of select="PropertyName"/>.Ticks; 
			} 
			set 
			{ 
				<xsl:value-of select="PropertyName"/> = new DateTime ( value ); 
			} 
		}
		</xsl:if>
	
		<xsl:if test="Type!='DateTime' and KnownClass='false' and CType='single'">
		[DataMember]
		public <xsl:value-of select="Type"/><xsl:text> </xsl:text><xsl:value-of select="PropertyName"/> { get; set; }
		</xsl:if>
		
		<xsl:if test="KnownClass='true' and CType='single'">
		[IgnoreDataMember]
		public <xsl:value-of select="Type"/><xsl:text> </xsl:text><xsl:value-of select="PropertyName"/> { get; set; }
		
		[DataMember]
		protected string <xsl:value-of select="Name"/>
		{ 
			get 
			{
				return <xsl:value-of select="PropertyName"/> == null ? string.Empty : <xsl:value-of select="PropertyName"/>._id; 
			}
			set
			{
				<xsl:value-of select="PropertyName"/> = new <xsl:value-of select="Type"/> ( ).Load ( value );
			}
		}
		</xsl:if>
		
		<xsl:if test="KnownClass='true' and CType!='single'">
		[IgnoreDataMember]
		public <xsl:value-of select="Type"/>[ ] <xsl:value-of select="PropertyName"/> { get; set; }
		
		[DataMember]
		protected string[ ] <xsl:value-of select="Name"/>
		{
			get
			{
				return <xsl:value-of select="PropertyName"/> == null ? new string [ ] { } :
					<xsl:value-of select="PropertyName"/>.Select ( v =&gt; v._id ).ToArray ( );
			}
			set
			{
				<xsl:value-of select="PropertyName"/> = value.Select ( v =&gt; new <xsl:value-of select="Type"/> ( ).Load ( v ) ).ToArray ( ); 
			}
		}
		</xsl:if>
		
		<xsl:if test="KnownClass='false' and CType!='single' and Type!='DateTime'">
		[DataMember]
		public <xsl:value-of select="Type"/>[ ] <xsl:value-of select="PropertyName"/> { get; set; }
		</xsl:if>
		
		
		<xsl:if test="KnownClass='false' and CType!='single' and Type='DateTime'">
		[IgnoreDataMember]
		public DateTime [ ] <xsl:value-of select="PropertyName"/> { get; set; }
		
		[DataMember]
		protected long[ ] <xsl:value-of select="Name"/>
		{
			get
			{
				return <xsl:value-of select="PropertyName"/> == null ? new long [ ] { } : <xsl:value-of select="PropertyName"/>.Select ( v =&gt; v.Ticks ).ToArray ( );
			}
			set
			{
				<xsl:value-of select="PropertyName"/> = value.Select ( v =&gt; new DateTime ( v ) ).ToArray ( );
			}
		}
		</xsl:if>
		
	
	</xsl:template>
</xsl:stylesheet>